package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import com.zzyl.vo.RoomTypeVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目相关接口")
public class NursingProjectController extends BaseController{

    @Autowired
    private NursingProjectService nursingProjectService;


    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult deletePro(@PathVariable Long id) {
        nursingProjectService.deletePro(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用")
    public ResponseResult enableOrDisable(
            @ApiParam(value = "项目ID", required = true) @PathVariable Long id,
            @ApiParam(value = "项目状态", required = true) @PathVariable Integer status) {
        nursingProjectService.enableOrDisable(id, status);
        return success();
    }

    @PutMapping
    @ApiOperation("编辑护理项目")
    public ResponseResult updateNursingProject(@RequestBody NursingProjectDto dto){
        nursingProjectService.updateNursingProject(dto);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据护理计划id查询护理项目")
    public ResponseResult findById(@PathVariable Long id){
        NursingProjectVo vo = nursingProjectService.findById(id);
        if(vo == null){
            return error("项目不存在");
        }
        return success(vo);
    }

    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult addNursingProject(@RequestBody NursingProjectDto dto){
        nursingProjectService.addNursingProject(dto);
        return success();
    }

    @GetMapping
    @ApiOperation("护理项目分页查询列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "护理项目名称"),
            @ApiImplicitParam(name = "pageNum",value = "当前页码",defaultValue = "1"),
            @ApiImplicitParam(name = "pageSize",value = "每页显示条数",defaultValue = "5"),
            @ApiImplicitParam(name = "status",value = "状态(0:禁用,1:启用)")
    })
    public ResponseResult findQuery(String name,Integer pageNum,Integer pageSize,Integer status){
        PageResponse result = nursingProjectService.findQuery(name,pageNum,pageSize,status);
        return success(result);
    }

    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult<List<NursingProjectVo>> findQueryList() {
        return success(nursingProjectService.findQueryList());
    }

}
